var app = getApp();
Page(Object.assign({},{
    data:{
        page : {
            isend : false,
            doing : false,
            doo : 'admin',
            pdata : {
                op : 'livelist',
                page : 1,
                status : 0,
            },
            waitf : 0,
            nodataf : 0,
        },
        datalist : [],
        isIPX : app.globalData.isIPX ? 1 : 0,
		siteroot : app.siteInfo.siteroot.replace('app/index.php', ''),uniacid: app.siteInfo.uniacid,
    },
    onShow:function(options){
        var self = this;
        
        self.setData({
            'page.pdata.page' : 1,
            'page.isend' : false,
        })
        
        app.com.auth(function(user){
            app.com.getPage(self,self.data.page,0,function(res){
                var data = res.data.data;
                self.setData({
                   datalist : data.list,
                   params : data.params,
                   inited : true,
                });

                wx.setNavigationBarTitle({
                  title: '直播',
                });
                
            },false,function(res){
                app.com.alert( res.data.message,function(){
                    if( res.data.errno == 2 ){
                        app.globalData.adminurl = app.com.getUrlArgs();
                        wx.navigateTo({
                            url : res.data.data.url
                        });
                    }
                });
            });

        });
        
    },
    onReachBottom : function(){
        var self = this;

        app.com.getPage(self,self.data.page,0,function(res){
            self.setData({
                datalist : self.data.datalist.concat(res.data.data.list)
            });
        });
    },
    deleteadmin( e ){
        var self = this;
        var id = e.currentTarget.dataset.id;
        var index = e.currentTarget.dataset.index;
        var postdata = {
            id : id,
            op : 'deletegoodsort',
        };
        app.com.confirm('确定删除此分类吗？',function(){
            app.com.http('admin','POST',postdata,0,true,'','',function(res){
                if ( !res.data.errno && res.data.errno !== undefined ) {
                    self.data.datalist.splice(index,1);
                    self.setData({
                        datalist: self.data.datalist
                    });
                    app.com.toast('已删除');
                }else{
                    app.com.alert(res.data.message);
                }
            });
        });

    },
    onPullDownRefresh: function () {
        if( this.data.isdown ) return false;
        this.data.isdown = true;
        
        this.onShow( this.data.options );
        this.data.isdown = false;
        wx.stopPullDownRefresh();
    },
    tab(e){
        var self = this;
        var index = e.detail.index;

        if( self.data.ising || index == self.data.page.pdata.status ) return false;
        self.data.ising = true;
        
        self.setData({
            datalist : [],
            'page.pdata.status' : index,
            'page.pdata.page' : 1,
            'page.isend' : false,
            'page.waitf' : 0,
            'page.nodataf' : 0
        });
        app.com.getPage(self,self.data.page,0,function(res){
            self.setData({
                datalist : res.data.data.list,
            });
        });
        self.data.ising = false;
    },
    scancode(e){
        var self = this;
        var id = e.currentTarget.dataset.id;
        var postdata = {
            id : id,
            op : 'scanlivecode',
        };
        
        app.com.http('admin','POST',postdata,0,true,'','',function(res){
            if ( !res.data.errno && res.data.errno !== undefined ) {
                var img = res.data.data.url;
                
                app.com.alert('可长按图片保存到手机，或者转发',function(){
                    wx.previewImage({
                        current: img,  
                        urls: [img] 
                    })
                });

            }else{
                app.com.alert(res.data.message);
            }
        });
    },
    settosend(e){
        var self = this;
        var i = e.currentTarget.dataset.i;
        var postdata = {
            id : this.data.datalist[i].id,
            op : 'setlivetosend',
        };
        app.com.confirm('确定设为已发奖吗？',function(){
            app.com.http('admin','POST',postdata,0,true,'','',function(res){
                if ( !res.data.errno && res.data.errno !== undefined ) {
                    self.setData({
                        ['datalist['+i+'].status'] : 1,
                    })
                }
                app.com.alert(res.data.message);
            });
        })
    },
    location : function( e ){
        app.com.location( e );
    },
    otherapp : function( e ){
        app.com.otherapp( e );
    },
    navigateto : function( e ){
        app.com.navigateto( e );
    },
    copy(e){
        app.com.copy( e );
    },
    redirectto : function( e ){
        app.com.redirectto( e );
    },    
    callphone : function(e){
        app.com.callphone( e );
    }
}))